<?php

error_reporting(0);

require_once("includes/pagetop.php");
include_once("updates/CommonFeatures.php");
include_once("includes/common_snippets.php");
include_once("lib/GenericCRUDOperations.php");

//print_r($_SESSION);
//die();
if(!isset($_SESSION['Allyfolio_User_ID']) || $_SESSION['Allyfolio_User_ID']==0)
{
    redirect("index.php");
}
else{
    if(isset($_SESSION['Allyfolio_User_ID']))
    {   
        if($_SESSION['Allyfolio_User_ID']<0){
            redirect("accountblocked.php");    
        }
    }
}



$patharr=explode("/",$_SERVER["REQUEST_URI"]);
$lastvars=end($patharr);
$afterWampToProjectRootPath=str_replace($lastvars,"",$_SERVER["REQUEST_URI"]);

//echo $_SERVER["SERVER_NAME"]." = ".$_SERVER["DOCUMENT_ROOT"]." = ".$_SERVER["REQUEST_URI"]."<br>".$afterWampToProjectRootPath;

$logObj=new Log();
$noofappsloadpermoreclick=1;
$noofsponcersdefault=5;


//CommonFeatures.php > Userdetails object
try{

    $loggedUserObj=new UserDetails();
    if (!isset($_SESSION["User_details"])){
        $_SESSION["User_details"]=$loggedUserObj->getUserDetails($_SESSION["Allyfolio_User_ID"],true);
    }
    //$pset=$loggedUserObj->getUserPrivacyDetails($loggedUserObj->userId);
    $loggedUserObj=$_SESSION["User_details"];
    //$loggedUserObj->latestFriendNotificationsArr=array(1=>"sumer",2=>"vikas");
/*echo "<pre>";
print_r($loggedUserObj);
echo "</pre>";
*/
    
}
catch(Exception $ex){
    $logObj->writeException("home.php Exception: => ".$ex->getMessage());
    die("Home.php fetching user details".$ex->getMessage());
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>AllyFolio | Home </title>



<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />

<script src="js/general.js"></script>
<script src="js/functions.js"></script>
<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
<link rel="stylesheet" href="bin/magicsuggest-1.3.1-min.css"/>
<!--<link rel="stylesheet" href="assets/magicsuggest/magicsuggestnew.css"/>-->
<script type="text/javascript" src="bin/jquery-1.8.3-min.js"></script>
<script type="text/javascript" src="bin/magicsuggest-1.3.1-min.js"></script>

<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
<script src="alertify/lib/alertify.min.js"></script>	
<script src="js/jquery1.10.2.min.js"></script>
<script src="js/modernizr.custom.56223.js"></script>

<script src="js/jquery.placeholder.js"></script>
<!-- For sharing popup -->
<script type="text/javascript" src="js/script.js"></script>


<!--
these 3 scrips are used to support IE Image upload
-->
<script type="text/javascript" src="js/jquery-1.9.0.js"></script>
<script type="text/javascript" src="js/ajaxupload.3.5.js"></script>
<script type="text/javascript" src="js/ieajaxupload.js"></script>

        
<!-- add location 
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false&libraries=places'></script>
<script src="js/locationpicker.jquery.js"></script>
-->
<!-- add location 
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>

-->


<script type="text/javascript">

function getLatLongForAddress(address,lociD){
    //alert(address);
    /*
    var mylatlong={'lat':0.00,'lng':0.00};
    var geocoder = new google.maps.Geocoder();    
    geocoder.geocode({ 'address': address}, 
        function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            var latitude = results[0].geometry.location.lat();
            var longitude = results[0].geometry.location.lng();
            mylatlong.lat=latitude;
            mylatlong.lng=longitude;
          } 
        }
    ); 
    pointmyaddress(lociD,mylatlong);
    */
    codeAddress(address,lociD); 
}
/*
function pointmyaddress(locID,locationpoints){
    alert("locationid: "+locID+" points: lat-"+locationpoints.lat+" long - "+locationpoints.lng)
    $('#'+locID).locationpicker({
    location: {latitude: locationpoints.lat, longitude: locationpoints.lng},	
    radius: 200
});
}*/
</script>

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>

function initialize() {
  
}

function codeAddress(address,locpath) {
    try{
        var geocoder;
        var map;
        geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng(-26.4503329, 74.6399125000000);
      var mapOptions = {
        zoom: 8,
        center: latlng
      }  
      map = new google.maps.Map(document.getElementById(locpath), mapOptions);
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            //alert("locationid: "+locpath+" points: lat-"+results[0].geometry.location.lat()+" long - "+results[0].geometry.location.lng())
          map.setCenter(results[0].geometry.location);
          var marker = new google.maps.Marker({
              map: map,
              position: results[0].geometry.location
          });
        } else {
          alert('Geocode was not successful for the following reason: ' + status);
        }
      });
  }
  catch(e){
    
  }
}

//google.maps.event.addDomListener(window, 'load', initialize);

</script>
    
	<div id="main_wrapper">

    <!--=================Header Start=======================-->

	<?php include_once "includes/main_header.php"; ?>

    <!--=================Header end=======================-->

    

    

    <script type="text/javascript">

    $(function() { $('input, textarea').placeholder();});

</script>

<style type="text/css">

    .chat_box{

        display:none;

    }

    .placeholder {

      color: #cccccc;

      }
/* emotions */
#emotionsdrp{
    position: absolute;
    padding: 4px;
}

#emotionsdrp div .em{
    cursor: pointer;
    padding: 2px;
} 
#emotionsdrp{
    background-color: gainsboro;
    width: 130px;
}
.em{
    
}
.em:hover{
    background-color: cadetblue;
    cursor:pointer;
}
</style>



<style type="text/css">

	.logo{ margin-top:10px;}

	.log_button{

	

	height:auto;

	margin:6px 0;

	overflow:hidden;

	float:left;

	margin-top:10px;

	

	}

	.new tr td{ vertical-align:top}

	

	textarea select{ border:1px solid #ccc}

	input textarea select{ border:1px solid #999}

    

    /* added by sujeet */

    .privacy-drp-menu{

        border:1px solid blue;

        display: none;

    }

    .privacy-drp-menu-items{

        border-bottom: 1px solid gray;

        cursor:pointer;

    }

.tagimage
{
width:25px; float:left; margin-right:6px
}
    .comment{
        width: 96%;
        height: 70px;

        padding-left: 4px;

        padding-right: 4px;
        overflow-y:auto;
        border:none; 

        background:none;
        background-color: #e8f6f6;
        border-top: 2px solid #E8F6E1;
        border-right: 2px solid #E8F6E1;
        border-left: 2px solid #E8F6E1;
        padding-top: 5px;

    }   
    .hiddenfile {
 width: 0px;
 height: 0px;
 overflow: hidden;
}
.commentbottom{
        width: 96%;
        padding-left: 4px;
        padding-right: 4px;
        overflow-y:auto;
        border:none; 

        background:none;
        background-color: #e8f6f6;
        border-left: 2px solid #E8F6E1;
        border-right: 2px solid #E8F6E1;
        border-bottom: 2px solid #E8F6E1;
        padding-top: 5px;
}
    .listenMe{

        width: 100%;

        text-align: center;

        padding-top: 14px;

        padding-bottom: 14px;

    }

    .feed{

        margin-top: 20px;

    }
    .para{
        line-height: 1.75 !important;
    }
    .countUpdates {
        /* background: #000; */
        padding: 1px;
        color: #000;
        /* border-radius: 5px; */
        padding: 0 5px;
    }
    .linktxt{
        color:blue;
    }
    .linktxt:hover{
        color:blue;
        text-decoration: underline;
    }
    
    /* notification popup */
                    #nav{list-style:none;margin: 0px;padding: 0px;}
                    #nav li {
                    float: left;
                    margin-right: 20px;
                    font-size: 14px;
                    font-weight:bold;
                    }
                    #nav li a{color:#333333;text-decoration:none}
                    #nav li a:hover{color:#006699;text-decoration:none}
    /*notification div */
    #notification_li
{
position:relative
}
#notificationContainer 
{
background-color: #fff;
border: 1px solid rgba(100, 100, 100, .4);
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
overflow: visible;
position: absolute;
/*top: 30px;*/
margin-left: -170px;
width: 400px;
z-index: 10;
display: none; // Enable this after jquery implementation 
}

#freqnotificationContainer 
{
    background-color: #fff;
    border: 1px solid rgba(100, 100, 100, .4);
    -webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
    overflow: visible;
    position: absolute;
    left: -87px;
    width: 480px;
    z-index: 10;
    display: none;  
}

// Popup Arrow
#notificationContainer:before {
content: '';
display: block;
position: absolute;
width: 0;
height: 0;
color: transparent;
border: 10px solid black;
border-color: transparent transparent white;
margin-top: -20px;
margin-left: 188px;
}
#notificationTitle
{
font-weight: bold;
padding: 8px;
font-size: 13px;
background-color: #ffffff;
/*position: fixed;*/
z-index: 1000;
width: 384px;
border-bottom: 1px solid #dddddd;
}
#notificationsBody
{
/*padding: 33px 0px 0px 0px !important;*/
height:300px;
overflow-x: auto;
}
#notificationFooter
{
background-color: #e9eaed;
text-align: center;
font-weight: bold;
padding: 8px;
font-size: 12px;
border-top: 1px solid #dddddd;
}

/* notification count*/
#notification_count 
{
padding: 3px 7px 3px 7px;
background: #cc0000;
color: #ffffff;
font-weight: bold;
margin-left: -10px;
border-radius: 9px;
-moz-border-radius: 9px;
-webkit-border-radius: 9px;
position: absolute;
margin-top: -11px;
font-size: 11px;
}

.notify{
    padding:10px;
}


.cmnt-initiate{
    
}
.cmnt-uploading{
    background:url(images/CmntMUpload.GIF);
    background-repeat:no-repeat;
    height:15px;
    width:20px;
}
.cmnt-upload_done{
    
}
.cmnt-upload_failed{
    
}
#cmntupload_filelist li{
    list-style: none;
    float: left;
    padding: 2px;
}
</style>

<link href="css/emoticons.css" rel="stylesheet" type="text/css"/>

<!-- custom post submission jquery by sujeet -->
<?php include_once("smiley.php");?>
<script type="text/javascript" src="js/smiley.js"></script>
<script src="js/autoloading.js"></script>
<script src="js/custom_popupshow.js"></script>
<script src="js/jquery.asyncpost.js"></script>
<script type="text/javascript" src="js/jwplayer.js"></script>
</head>



<body style="background-color: #E8F6F6;">

<?php
try{
    $oGenericCrudOperations= new CRUDOperations();
    $oGenericCrudOperations->notifyMyFriendsBirthdays($loggedUserObj->userId);
}catch(Exception $ex){
    //echo "testing...";    
}

//data from user config
$userSettings=array(
                'emailid'=>$loggedUserObj->emailId,
                'id'=>$_SESSION["Allyfolio_User_ID"],
                'privacy_settings'=>$loggedUserObj->feedsetting
                );                

$_SESSION['user_settings']=$userSettings;
$mineuid=$loggedUserObj->userId;

$myLastNotificationID=0;

 

include_once("updates/ReadNotifications.php");
?>

    <!--=================Body Contain Start=======================-->

    <div class="wrapper">

      <div class="header">

        <div class="contain-wrap2" style="margin-top:30px; width:100%; ">

          

        <div class="home_left">
            <?php include_once("home_leftsidebar.php"); ?>
		</div>

		<div class="home_right">

		<table width="100%" border="0">

			<tr>

				<td>
                    <?php //echo $loggedUserObj->userId; ?>
                    <table width="100%">
                        <tr>
                            <td width="120px">&nbsp;</td>
                            <td width="520px">
                                <div id="stupdthandler"></div>
                                <div id="light_stupdtsec">
                    <form id="frmstupdt" name="frmstupdt" action="ajax/update_data.php?action=st_update" enctype="multipart/form-data" > 
                        <input type="hidden" id="nPostType" name="nPostType" value="1" />
					<div class="status">

						<div class="status_top1">

                            <?php

                            $oDropfilters= new CGetFilters();

                            $privacyTypes=$oDropfilters->getFilters("privacy_types");

                            //print_r($privacyTypes);

                            ?>

                            <div id="statusshare">

                                <input type="text" id="ajx_status_update" name="ajx_status_update" placeholder="Status Update/Write what you think.." />

                                <div id="status_tagging" style="display: none;">

                                    <div style="border-top: dashed 1px gray;">

                                        <input type="text" id="st_taggedusers" name="st_taggedusers" placeholder="Enter friends name.." />

                                        <input type="hidden" id="sttaggedusers" name="sttaggedusers" />

                                    </div>

                                    

                                </div>
                                
                                <div id="status_emotions" style="display: none;">
                                    <div style="border-top: dashed 1px gray;">
                                    <!--
                                        <div id="st_emotionsfeeling_txt" style="display: none;">
                                            <input type="text" id="st_emotionsfeeling" name="st_emotionsfeeling" placeholder="what you do.." onclick="return openEmotionCategoriesList();"/>
                                        </div>
                                        -->
                                        <div id="st_emotionsfeeling_div" onclick="return openEmotionCategoriesList();" style="height:25px"></div>
                                        <input type="hidden" id="stemotionsfeeling" name="stemotionsfeeling" />
                                    </div>
                                    <div id="emotionslist" style="width: 150px;position: absolute;display:none"></div>
                                    

                                </div>
                                <span id="post_location" style="padding: 5px;"></span>

                            </div>

							

								<div class="stat_bot">
                                    <div id="image_loader_div" style="display:none;"><img src="images/LoadingBar.gif" width="64px" height="64px"/></div>

                                    <div id="post_media_thumb_div">

                                        

                                    </div>

                                    <br />

									<ul>

										<li >

                                            <select id="prvset" id="prvset" onchange="setPrivacySetting(this.value)" class="blueuicontrol">

                                                <?php

                                                 $myprivacysetting=0;

                                                if (!empty($_SESSION['user_settings']['privacy_settings'])) {

                                                    $myprivacysetting = trim($_SESSION['user_settings']['privacy_settings']);

                                                }

                                                if(is_numeric($myprivacysetting) && $myprivacysetting>0){

                                                    $defaultSelected=$myprivacysetting;

                                                }

                                                else{

                                                    $defaultSelected=1; //privacy type assigned    

                                                }

                                                foreach($privacyTypes as $privacyType){

                                                    if($privacyType["ID"]==$defaultSelected){

                                                        $selected=true;

                                                    }

                                                    else if($privacyType["keyword"]=="public"){

                                                        $selected=true;

                                                    }

                                                    else{

                                                        $selected=false;

                                                    }

                                                        

                                                        

                                                    ?>

                                                    <option value="<?php echo $privacyType["ID"] ?>" <?php if($selected){  ?>selected="true" <?php } ?> >

                                                        <?php echo $privacyType["Privacy_Type_Title"]; ?> 

                                                    </option>

                                                    <?php

                                                }

                                                ?>

                                            </select>
                                            <div id="st_myclusters" style="display:none">
                                                <select id="st_share_with_cluster" name="st_share_with_cluster" class="blueuicontrol">                                                    
                                                </select>
                                            </div>
        
        
                                        </li>

										<li>

											<a href="javascript:void(0)" onclick="return openFile('status_update_file')"><img src="images/ico/5.png" /></a>

											<div id="image_loader_div" style="display:none;"><img src="images/LoadingBar.gif" width="64px" height="64px"/></div>

											<input type="file" id="status_update_file" name="status_update_file" style="display:none;" accept="audio/*,video/*,image/*" onchange="return uploadMedia('1','status_update_file','frmstupdt','post_media_thumb_div','status_file_hidden');" />

											<input type="hidden" name="status_file_hidden" id="status_file_hidden" value="" />

											<!-- 1 for status Update -->

										</li>

										<li>

											<a href="javascript:void(0)" onclick="return openFile('status_update_file')"><img src="images/ico/6.png" /></a>

										</li>

										<li>
                                            <a href="javascript:void(0)" onclick="return showEmotionsBox();">
                                                <img src="images/ico/7.png" />
                                            </a>
                                        </li>

										<li>

                                            <a href="javascript:void(0)" onclick="showMyLocationBox();" title="Add Location">
                                                <!-- showAddLocationBox() -->
                                                <img src="images/ico/8.png" />

                                            </a>

                                        </li>

										<li>

                                            <a href="javascript:void(0)" onclick="showStatusTaggedBox();" title="Add Location">

                                                <img src="images/ico/9.png" />

                                            </a>

                                        </li>

										<li style="float:right;">

                                            <a href="add_blog.php">

                                                <!--<span style="padding-right:5px;">Create Blog</span>-->    
                                                <input type="button" class="blueuicontrol" style="width:100px!important" value="Create Blog" />
                                            </a>

											<input type="button" id="#post_s" class="blueuicontrol" style="width:80px!important;cursor: pointer;" onclick="updateStatus('frmstupdt');" value="send" />

											<!--

	                                        <span id="#post_s" onclick="updateStatus('frmstupdt');">send</span>

	                                        -->

                                        </li>

									</ul>

									<div class="clearfix"></div>

                                    <input type="hidden" id="locstr" name="locstr" value="NONE" />

							</div>

						</div>

					</div>

                    <div id="errconsole"></div>

                    </form>
                    
                    <div id="light_mylocation" style="display:none">
                        <iframe src="mylocation.php" width="500px" height="250px"></iframe>
                    </div>  
                    <div id="light_mylocationpost" style="display:none">
                        <iframe src="mylocation.php?p=1" width="500px" height="250px"></iframe>
                    </div>
                </div>        
                            </td>
                            <td>
                                &nbsp;
                            </td>
                        </tr>
                    </table> 
                    
                    
				</td>

				<td></td>

			</tr>

		</table>

        

        <style>

        #tweets { border-left:1px solid gray; padding-left:20px}

        #overlay { position: absolute; left: 168px; top: 87px;

           width: 408px; height:386px; background: url("../images/transpBlue_overlay.png"); }

        #overlay img { position:relative; left:200px; top:189px; }   

        </style>

        
              
        
                    
                
        <!-- js scrolling -->

        <div id="tweets">

           <!-- Tweets will get loaded from jQuery -->

        </div>

        <div id="viewmore" style="background-color:gray; width:84%;pointer:cursor">

            <div style="text-align: center;padding-top: 10px;padding-bottom: 10px;pointer:cursor" onclick="return OnViewMore('<?php echo $loggedUserObj->userId; ?>','<?php echo $loggedUserObj->feedsetting; ?>',false,postTypeToRead.feeds);">

                View More >>

            </div>

           <!-- Tweets will get loaded from jQuery -->

        </div>

        <!--<div id="overlay">

           <img src="images/ajax-loader.gif" />

        </div>-->

        <!-- js scrolling -->

        

        <script type="text/javascript">

            $('#ajx_status_update').keypress(function (e) {

              if (e.which == 13) {

                ust("frmstupdt");    

                //$('form#frmstupdt').submit();

                return false;    //<---- Add this line

              }

            });

            // Set the size for each page to load

            requserid='<?php echo $loggedUserObj->userId; ?>';

            requserprivacysetting='<?php echo $loggedUserObj->feedsetting; ?>';

            

            var pageSize = 15;              

            // Username to load the timeline from

            var username = 'marcofolio';             

            // Variable for the current page

            var currentPage = 1;            

            // Loads the next tweets

            var loadTweets = function(lsttweet) {

               //getNewsFeeds('<?php echo $loggedUserObj->userId; ?>','0','<?php echo $loggedUserObj->feedsetting; ?>');

               OnViewMore('<?php echo $loggedUserObj->userId; ?>','<?php echo $loggedUserObj->feedsetting; ?>',true,postTypeToRead.feeds,0);

            };

            

            // First time, directly load the tweets

            loadTweets(0);
            
            var feedsMinutesT=1000*60*2;
            var feedsTesting=1000;
                var myNotificationInterval=setInterval(function(){myFeedTimer('<?php echo $loggedUserObj->userId; ?>')},feedsTesting);
                
                function myFeedTimer(uid) {
                    if(!isDebugChecking)
                        isNewFeedsAreThere('<?php echo $loggedUserObj->userId; ?>','<?php echo $loggedUserObj->feedsetting; ?>',postTypeToRead.feeds,0);
                }

        </script>
		</div> 
</div>
    </div>

    <div class="clearfix"></div>

    </div>
    <div class="clearfix"></div>

    <?php include_once "common_divs_include.php"; ?>

    <?php include_once "includes/footer.php"; ?>

    
<div id="tempCmntUploadStatus">
    <input type="hidden" id="currentCommentUploadername" value="NONE" />
</div>
</div>


    <!--=================Footer end=======================-->

    <script type="text/javascript">
   
    
    /*
    $("#uploadcmntfile").live("change",function(event) 
    {    
            
    });
    */
    
	    function uploadMyComment(event){
            var formObj = $("#"+$("#currentCommentUploadername").val());
            if(formObj){
                var uploadCmntPostId=formObj.find("#cmid").val();
                var cmntpostid=getNumberFromString(uploadCmntPostId);
            	var formURL = formObj.attr("action");
                alert("clicked");
            	if(window.FormData !== undefined)  // for HTML5 browsers
            	{
            	   alert("html5 browser");
                   var formData = new FormData();
                    // Main magic with files here
                    formData.append('uploadcmntfile', $(formObj).find('#uploadcmntfile')[0].files[0]); 
        
            		
            		$.ajax({
                    	url: formURL,
            			type: "POST",
            			data:  formData,
            			mimeType:"multipart/form-data",
            			contentType: false,
                	    cache: false,
            			processData:false,
            			success: function(data, textStatus, jqXHR)
            		    {
            		      alert(data);
                          
            		    },
            		  	error: function(jqXHR, textStatus, errorThrown) 
            	    	{
            	    	  alert(data);
            	    	} 
                        	        
            	   });
                    event.preventDefault();
               }
               else  //for olden browsers
        	   {
        	   alert("old browser")
                var btnUpload = $(formObj).find('#uploadcmntfile');
                var status = $('#status');
                new AjaxUpload(btnUpload, {
                    action: formURL,
                    name: 'uploadcmntfile',
                    onSubmit: function(file, ext) {
                        alert("on submit starts");
                        //                if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {
                        //                    // extension is not allowed 
                        //                    status.text('Only JPG, PNG or GIF files are allowed');
                        //                    return false;
                        //                }
                        //newly added
                        fileuploadrequest_c++;
                        var uploadFileCounter = "uploadc-" + fileuploadrequest_c;
                        var UploadingList = "<div id='" + uploadFileCounter + "'>" + file + "</div>";
            
                        this.setData({ X_FILENAME: fileuploadrequest_c });
                        //add row for processing
                        var fsize = "   -";
                        //alert(file);
                        addUploadProcessingRow(fsize, uploadFileCounter, file);
                        alert("on submit ends");
                    },
                    onComplete: function(file, response) {
                    	alert("on complete start");
                        var responseForFile = response;
                        var responseTextArr = responseForFile.split("$");
                        var responseTextVal = responseTextArr[1];
                        var responseForFile = responseTextArr[0];
                        var responseTextSize = responseTextArr[2];
            
                        var requestedFileResponseForFile = "uploadc-" + responseForFile;
            
                        //add response from server to file progress
                        setResponseOnUploadProgress(responseTextVal + "$" + responseTextSize, requestedFileResponseForFile);
                        alert("on complete ends");
                    }
                });
        	
        	}
        }
    
    }

    	function uploadMedia(postType,fileControlId,formName,containerDiv,hiddenField)

		{

			if(document.getElementById(fileControlId).value!="")

			{

				document.getElementById("image_loader_div").style.display="";

				formdata = false;

				if (window.FormData) {

					formdata = new FormData(document.getElementById(formName));

				}

			

				var xmlhttp;

						

				if (window.XMLHttpRequest)

				{// code for IE7+, Firefox, Chrome, Opera, Safari

					xmlhttp=new XMLHttpRequest();

				}

				else

				{// code for IE6, IE5

					xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

				}

				xmlhttp.onreadystatechange=function()

				{

					if (xmlhttp.readyState==4 && xmlhttp.status==200)

					{	

						var res=xmlhttp.responseText;	

						resArr=res.split("|~|");

						var divContent="";

						if(resArr[0]=="SUCCESS")

						{

							////document.getElementById("blog_display_img").src="uploads/temp_blog_images/"+resArr[1];

//							//document.getElementById("blog_image").src="uploads/image_crop.php?image=/uploads/blog_images/"+resArr[1]+"&width=982&height=571&cropratio=982:571";

//							var divContent='<div class="upVid">';

//							divContent +='<div class="vid"><a href="'+resArr[1]+'" class="PagePhotoGallery" data-fancybox-group="PagePhotoGallery"><img src="uploads/image_crop.php?image=/'+resArr[1]+'&width=93&height=91&cropratio=93:91" /></a></div>';

//							divContent +='</div>';

//							

//							document.getElementById("page_photos_div").innerHTML=document.getElementById("page_photos_div").innerHTML+divContent;

							

							divContent +='<div class="post_media_thumb" data-image="'+resArr[1]+'">';

							var extArr=["vob","mp4","3gp","mp3"];

							var pathArr=resArr[1].split(".");

							if(jQuery.inArray( (pathArr[pathArr.length-1]), extArr )>=0)

							{

								divContent +='<img src="uploads/image_crop.php?image=/images/dummy_video.jpg&width=40&height=40&cropratio=40:40"/>';

							}

							else

							{

								divContent +='<img src="uploads/image_crop.php?image=/'+resArr[1]+'&width=40&height=40&cropratio=40:40"/>';

							}

							divContent +='<a href="javascript:void(0)" onclick="return deleteMedia(\''+resArr[1]+'\',\''+hiddenField+'\');">X</a>';

							divContent +='</div>';

							

							document.getElementById(containerDiv).innerHTML=document.getElementById(containerDiv).innerHTML+divContent;

							document.getElementById(hiddenField).value=document.getElementById(hiddenField).value+resArr[1]+",";

							document.getElementById("image_loader_div").style.display="none";

						}

						else

						{

							document.getElementById("image_loader_div").style.display="none";

							alertify.alert(resArr[1]);

						}

					}

				}	

				xmlhttp.open("POST","ajax/upload_media.php",true);

				xmlhttp.send(formdata);

			}

		}

		

		function deleteMedia(mediaPath,hiddenField)

		{

			$("div").find("[data-image='" + mediaPath + "']").remove(); //find data-image

			var updatedMedias=$("#"+hiddenField).val().replace(mediaPath, " ");

			var mediaArr=updatedMedias.split(",");

			var currentMedias="";

			for(i=0;i<mediaArr.length;i++)

			{

				if(mediaArr[i].trim()!="")

				{

					currentMedias=currentMedias+mediaArr[i]+","

				}

			}

			document.getElementById(hiddenField).value=currentMedias;

		}

		

		function openFile(fileControlId)

		{

			$("#"+fileControlId).trigger("click");

		}

    

        function showHideChatBuddies(){

            var buddyListDisplay= $(".cc2").css("display");

            if(buddyListDisplay!="none"){

                $(".cc2").css("display","none");

            }

            else{

                $(".cc2").css("display","block");

            }

        }

    </script>

    <script>

        $( "#frmstupdt" ).submit(function( event ) {

          // Stop form from submitting normally

          event.preventDefault();

          // Get some values from elements on the page:

          ust("frmstupdt");

        });

        function updateStatus(){

            ust("frmstupdt");

        }

        function showEmotionsBox(){     
            
            if($("#status_emotions")){
                if($("#status_emotions").css("display")=="none"){
                    $("#status_emotions").show();
                    $("#emotionslist").hide();
                }
                else{
                    $("#status_emotions").hide();
                }
            }
            
            
        }
        function openEmotionCategoriesList(){
            if($("#emotionslist")){
                if($("#emotionslist").css("display")=="none"){
                    getEmotionsDropdown();
                    $("#emotionslist").show();
                }
                else{
                    $("#emotionslist").hide();
                }
            }
        }
    </script>

<!-- <script type="text/javascript" src="js/jquery.min.1.9.js"></script> -->
<script type="text/javascript" >


/*code added by jodhraj for home search bar*/

$(function() {
    var ms5 = $('#homesearch').magicSuggest({
            width: 300,
            value: '',
            id: 'userfriendids',
            maxSelection:1,
            style:'width: 535px;border: none;background-color: white;margin-top: 1px !important;',
            data: 'ajax_search/homesuggestusers.php' 
        });
        
         $(ms5).on('selectionchange', function(){
              selectedvalue=JSON.stringify(this.getValue());
              selectedvalue=selectedvalue.replace('["','');
              selectedvalue=selectedvalue.replace('"]','');
              window.location='dna.php?t='+selectedvalue;
            });
});
/*code ended jodhraj here */

var showhidefreqpopup=0;


function makeClickOnItem(evt)
{
    var el;
    if(!evt)
    {
        evt = window.event;
        el = evt.srcElement;    
    }else  if(evt)
    {
        el = evt.target;   
    }
    switch(el.id)
    {
        case "left":
        fireKey(el);
        break;   
        case "right":
        fireKey(el);
        break;     
        default:
        fireKey(el);
        break;
    }
}

function fireKey(el)
{
    var key;
    switch(el.id)
    {
        case "left":
        key = 37;
        break;
        case "right":
        key = 39;
        break;
        default:
        key = 39;
        break;
            
    }
    if(document.createEventObject)
    {
        var eventObj = document.createEventObject();
        eventObj.keyCode = key;
        el.fireEvent("onkeydown", eventObj);   
    }else if(document.createEvent)
    {
        var eventObj = document.createEvent("Events");
        eventObj.initEvent("keydown", true, true);
        eventObj.which = key;
        el.dispatchEvent(eventObj);
    } 
}

function getNumberFromString(str){
    if(parseInt(str.replace( /[^\d.]/g,''))>0){
        return str.replace( /[^\d.]/g,'');
    }
    else{
        return 0;
    }
}        

function uploadCmnt(idval){
        alert("clicked");
        cufname="multiformCmntUpload"+idval;
        $("#currentCommentUploadername").val(cufname);
        var formObj = $("#"+cufname);
        var uploadCmntPostId=formObj.attr('id');
        var cmntpostid=getNumberFromString(uploadCmntPostId);
        formObj.find("#cmid").val(cmntpostid);
        var urltopost='uploadImage.php?cmpid='+cmntpostid+"&action_str=commentimage";
        formObj.attr("action",urltopost);
        
        $(formObj).find("#uploadcmntfile").click();
            
    }

$(document).ready(function()
{
    //$(".aftaguid").live("click",function() 
//    {
//            var username=$(this).find('.afid').val();
//            window.location.href="dna.php?t="+username;            
//    });


    
   // $(".upcmntfile").live("click",function(event) 
//    {
//        $(formObj).find("#uploadcmntfile").click();
//    });
                             
    $(".addname").live("click",function(event) 
        {
            //alert("tag friend clicked");
            var username=$(this).attr('title');
            var cthredid=$(this).find(".hidthreadid").val();
            var cthredafid=$(this).find(".hidafid").val();            
            var old=$("#"+cthredid+"_txtcomment").html();
                        
            var content=old.replace(word,""); 
            $("#"+cthredid+"_txtcomment").html(content);
            //var E="<a class='red aftaguid' contenteditable='false' href='#' >"+username+" <input type='hidden' class='afid' value='"+cthredafid+"'/> </a>";
            var E="<a id='right-"+cthredid+"' class='red aftaguid' contenteditable='false' href='dna.php?t="+cthredafid+"'>"+username+"</a>";
            $("#"+cthredid+"_txtcomment").append(E);
            $("#"+cthredid+"_flist").hide();
            $("#"+cthredid+"_msgbox").hide();
            //$("#"+cthredid+"_txtcomment").prop("selectionStart", $("#"+cthredid+"_txtcomment").text().length).focus();
            makeClickOnItem(event);
            $("#"+cthredid+"_txtcomment").find(".aftaguid:last").focus();
        }
    );


    

    $("#notification_li #notificationLink").click(function()
    {
//added by jodhraj
        
        
        if(showhidefreqpopup==0)
        {
            showhidefreqpopup=1;    
            showFriendRequests();
        }
        else{
           $("#notification_li #freqnotificationContainer").hide();
           showhidefreqpopup=0; 
        }
        //alert(totalbdayupdated);
        /*if(totalbdayupdated>0){
            $("#notification_li #notificationContainer").fadeToggle(300);
            $("#notification_li #notification_count").fadeOut("slow");
            totalbdayupdated=0;    
            markAsReadAlerts("birthday_alerts");
        }
        else{
            alertify.alert("No birthday notification found..");
           $("#notification_li #notificationContainer").hide(); 
        }
        
        return false;
*/
    });
    
    //Document Click hiding the popup 
    $(document).click(function()
    {
        $("#notification_li #freqnotificationContainer").hide();
        showhidefreqpopup=0;
    });
    
    //Popup on click
    $("#notification_li #freqnotificationContainer").click(function()
    {
        showhidefreqpopup=0;
        return false;
    });
/*
    $(document).click(function()
    {
        $("#notification_li #notificationContainer").hide();
        totalbdayupdated=0;
    });
    
    //Popup on click
    $("#notification_li #notificationContainer").click(function()
    {
        totalbdayupdated=0;
        return false;
    });
*/
    // New Notifications
    $("#all_notification_li #notificationLink").click(function()
    {
        if(parseInt(notJson.err)==200){
            totalnewnotifictionsupdated=notJson.msg.length;
            var notificationLayout="<div class='not-activity' >";
                  notificationLayout+="<div style='float:left;width:100%' ><table style='border-bottom:1px solid gray;padding-bottom: 10px;padding-top: 10px;' width=100% cellspacing=2 cellpadding=4 >";
                    notificationLayout+="<tr>";
                        notificationLayout+="<td rowspan='2'>";
                            notificationLayout+="<img src='{0}' width=50 alt='profile-image'/>"; //img
                        notificationLayout+="</td>";
                        notificationLayout+="<td>";
                            notificationLayout+="{1}"; // source name
                        notificationLayout+="</td>";
                        notificationLayout+="<td>";
                            notificationLayout+="<div style='float:right;' onclick='markActRead({5});'>X</div>";
                            notificationLayout+="<div style='display:none;'><input type='hidden' class='not-info' value='{2}'></div>";
                        notificationLayout+="</td>";
                    notificationLayout+="</tr>";
                    notificationLayout+="<tr>";
                        notificationLayout+="<td>";
                            notificationLayout+="{3} (<a href='{6}'>view link</a>)"; //text
                        notificationLayout+="</td>";
                        notificationLayout+="<td>";
                            notificationLayout+="{4}"; //ago
                        notificationLayout+="</td>";
                    notificationLayout+="</tr>";
                notificationLayout+="</table></div>";
            notificationLayout+="</div>";
            
            
            var notInfo="{}";
            var textReplaced="";
            var agoText="";
            
            //alert(totalbdayupdated);
            if(totalnewnotifictionsupdated>0){
                var notJsonAlert="";
                var nTcount=0;
                for(n_alert in notJson.msg){
                    if(nTcount<totalnewnotifictionsupdated){
                        notJsonAlert=notJson.msg[n_alert];
                        notInfo="{aid:"+notJsonAlert.aid+",atid:"+notJsonAlert.atid+"}";
                        textReplaced=getReplacedText(notJsonAlert.template,notJsonAlert);
                            
                        templateText=notificationLayout.format(notJsonAlert.S_PicPath,notJsonAlert.slink,notInfo,textReplaced,agoText,notJsonAlert.aid,notJsonAlert.red_url);
                        //$("#all_notification_li #notificationsBody").append("<div class='notify'>"+templateText+"</div>");
                        $("#all_notification_li #notificationsBody").prepend("<div class='notify-{0}'>".format(notJsonAlert.aid) +templateText+"</div>");
                        nTcount++;
                    }
                    
                }
                
                $("#all_notification_li #notificationContainer").show(300);
                $("#all_notification_li #notification_count").html(totalnewnotifictionsupdated);
                $("#all_notification_li #notification_count").fadeOut("slow");
                notJson={"err": 404,"msg": []};
                
                totalnewnotifictionsupdated=0;    
                //markAsReadAlerts("birthday_alerts");
            }
            else{
                if($("#all_notification_li #notificationsBody").find(".notify").length>0){
                    $("#all_notification_li #notificationContainer").show(300);
                    $("#all_notification_li #notification_count").html(totalnewnotifictionsupdated);
                    $("#all_notification_li #notification_count").fadeOut("slow");
                }
                else{
                    alertify.alert("No new notification found..");
                    $("#all_notification_li #notification_count").html("");
                    $("#all_notification_li #notificationContainer").hide();
                }
            }
        }
        else{
            if($("#all_notification_li #notificationsBody").find(".notify").length>0){
                $("#all_notification_li #notificationContainer").show(300);
                $("#all_notification_li #notification_count").fadeOut("slow");
            }
            else{
                alertify.alert("No new notification found..");
                $("#all_notification_li #notification_count").html("");
                $("#all_notification_li #notificationContainer").hide();
            }
        }
        
        
        return false;
    });
    
    //Document Click hiding the popup 
    $(document).click(function()
    {
        $("#all_notification_li #notificationContainer").hide();
        //totalnewnotifictionsupdated=0;
    });
    
    //Popup on click
    $("#all_notification_li #notificationContainer").click(function()
    {
        //totalnewnotifictionsupdated=0;
        return false;
    });

});

function uploadimg(frmid){
    //if(document.getElementById(frmid)){
        $('#multiformCmntUpload').find("#cmid").val(getNumberFromString(frmid));
        $('#multiformCmntUpload').find("#file").trigger('click'); 
    //}
}
function uploadMyCommentFile(event){
    var selectedFile=$("#file").val();
    if(selectedFile!=""){
        alert("change found"+selectedFile);
        //alert("kk"+$('#multiformCmntUpload').find("#cmid").val());
        var urltopost="uploadImage.php?cmid="+$('#multiformCmntUpload').find("#cmid").val()+"&action_str=commentimage";
        alert(urltopost);
        var cmntid=getNumberFromString($('#multiformCmntUpload').find("#cmid").val());
        alert(cmntid);
        var formURL = urltopost;
        alert(formURL);
        
        $("#multiformCmntUpload").attr("action",formURL);
        $("#multiformCmntUpload").submit();
    }    
}

//getBirthdayNotifications('<?php echo $_SESSION['Allyfolio_User_ID']; ?>');
</script>
<div>

</div>
</body>

</html>